package com.csc.contact.checkbill.service;


import com.csc.contact.checkbill.entity.ReconciliationInfo;
import com.csc.contact.checkbill.mapper.ReconciliationMapper;
import com.hollycrm.hollybeacons.system.db.mybatis.support.BaseServiceImpl;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * author zhanglei
 * createDate 2019-06-17
 * Description 对账文件信息操作类
 */

@Service("reconciliationservice")
public class ReconciliationServiceImpl extends BaseServiceImpl<ReconciliationMapper, ReconciliationInfo> {

    private final static Logger LOGGER = Logger.getLogger(ReconciliationServiceImpl.class);

    /**
     * 枢纽传过来的对账信息入库
     *
     * @param reconciliationInfos
     */
    public void batchReconciliationInfo(List<ReconciliationInfo> reconciliationInfos) {
        try {
            LOGGER.info("List<ReconciliationInfo>=====" + reconciliationInfos.size());
            LOGGER.info("入库返回状态====" + this.baseMapper.saveReconcInfo(reconciliationInfos));
        } catch (Exception e) {
            LOGGER.info("批量入库异常====", e);
        }
    }

    public boolean trucateTable() {
        int number = this.baseMapper.truncateTable();
        if (number == 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取对账信息的所有记录数据
     *
     * @return
     */
    public int queryReconCount() {
        return this.baseMapper.queryReconCount();
    }

    /**
     * 获取对账信息的所有记录数据
     *
     * @return
     */
    public int queryReconCountByProvide(String originProvide) {
        try {
            return this.baseMapper.queryReconCountByProvide(originProvide);
        }catch (Exception e){
            LOGGER.info("获取对账信息表中单个省份的记录异常", e);
            return 0;
        }
    }


    /**
     * 获取一条对账信息记录
     *
     * @param startPostion
     * @return
     */
    public ReconciliationInfo queryReconInfo(int startPostion) {
        return this.baseMapper.queryReconInfo(startPostion);
    }

    /**
     * 获取指定省份中的一条对账信息记录
     *
     * @param params
     * @return
     */
    public ReconciliationInfo queryReconInfoByProvince(Map params) {
        return this.baseMapper.queryReconInfoByProvince(params);
    }

    //查询对账表中当前省份所有数据
    public List<ReconciliationInfo> queryAllReconInfoByProvince(String cardProvince){
        return this.baseMapper.queryAllReconInfoByProvince(cardProvince);
    };
    /**
     * 获取对账文件入库中的去重省份列表
     *
     * @return
     */
    public List<String> queryProvide() {
        try {
            return this.baseMapper.queryProvide();
        } catch (Exception e) {
            LOGGER.info("获取对账文件中的省份列表异常", e);
            return null;
        }
    }

}
